package com.rgp.servicedriveruser.service.impl;

import com.rgp.internalcommon.dto.DriverUserWorkStatusDto;
import com.rgp.internalcommon.dto.ResponseResult;
import com.rgp.internalcommon.response.DriverStatus;
import com.rgp.internalcommon.response.DriverStatusResponse;
import com.rgp.servicedriveruser.mapper.DriverUserWorkStatusMapper;
import com.rgp.servicedriveruser.pojo.DriverUserWorkStatus;
import com.rgp.servicedriveruser.service.DriverUserWorkStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author nhp
 * @version 1.0
 * @description TODO
 * @date 2024-04-17 22:24
 */
@Service
public class DriverUserWorkStatusServiceImpl implements DriverUserWorkStatusService {

    @Autowired
    DriverUserWorkStatusMapper driverUserWorkStatusMapper;
    @Override
    public ResponseResult changeStatus(DriverUserWorkStatusDto driverUserWorkStatusDto) {

        Long driverId = driverUserWorkStatusDto.getDriverId();
        Integer workStatus = driverUserWorkStatusDto.getWorkStatus();

        Map<String, Object> map = new HashMap<>();
        map.put("driver_id",driverId);
        List<DriverUserWorkStatus> list = driverUserWorkStatusMapper.selectByMap(map);
        DriverUserWorkStatus statusEntity = list.get(0);
        //更改司机的工作状态
        statusEntity.setWorkStatus(workStatus);
        driverUserWorkStatusMapper.updateById(statusEntity);
        return ResponseResult.success();
    }

    @Override
    public ResponseResult<DriverStatusResponse> getStatusByDriverIds(List<Long> driverIds) {
        List<DriverStatus> status = driverUserWorkStatusMapper.getStatusByDriverIds(driverIds);
        DriverStatusResponse response = new DriverStatusResponse();
        response.setStatus(status);
        return ResponseResult.success(response);
    }
}